package com.madou.dbtool.mysql.language;

import com.madou.common.annotation.HideClass;
import com.madou.dbtool.language.enums.ContentTypeEnum;
import com.madou.dbtool.relationship.language.RBSqlContentTypeParser;
import com.madou.dbtool.ui.editor.skin.MEditorSkin;
import com.madou.dbtool.ui.editor.views.CommonSqlParserFactory;
import com.madou.dbtool.ui.list.loader.ListDataLoader;
import com.mysql.cj.MysqlType;

import java.awt.*;
import java.util.Map;

/**
 * Mysql sql语法高亮解析
 * @author miukoo
 */
@HideClass("mysqlSqlContentTypeParser")
public class MysqlSqlContentTypeParser extends RBSqlContentTypeParser {
    public static final MysqlKeywordTrieLoader MYSQL_KEYWORD_TRIE_LOADER = new MysqlKeywordTrieLoader();

    @Override
    public ListDataLoader getTrieLoader() {
        return MYSQL_KEYWORD_TRIE_LOADER;
    }

    @Override
    public Map<String, Color> getDynamicKeyword() {
        return MYSQL_KEYWORD_TRIE_LOADER.getDynamicKeyword();
    }

    @Override
    public void addWord(String keyword) {
        MYSQL_KEYWORD_TRIE_LOADER.addWord(keyword);
    }

    @Override
    public void initDBType() {
        for (MysqlType type : MysqlType.values()) {
            keywords.put(type.getName(), MEditorSkin.SKIN.getDataTypeForegroundColor());
            keywords.put(type.getName().toString(), MEditorSkin.SKIN.getDataTypeForegroundColor());
        }
    }

    public ContentTypeEnum getContentTypeEnum() {
        return ContentTypeEnum.MYSQL;
    }


    /**
     * 单例
     */
    public static final MysqlSqlContentTypeParser INSTANCE = new MysqlSqlContentTypeParser();
    static {
        CommonSqlParserFactory.add(INSTANCE);
    }
}
